Determining Whether One Shape Contains Another
QuickDraw GX also provides three functions to help you determine whether one area contains another:
The sample function in Listing 4-11 creates a small circular path and a larger, donut-shaped path to test for containment.
- The
GXContainsRectangle
function determines whether one rectangle contains another.- The
GXContainsBoundsShape
function determines whether the area covered by a rectangle contains the area covered by a shape.- The
GXContainsShape
function determines whether the area covered by one shape contains the area covered by another shape.
Listing 4-11 Creating a path shape with two contours and a smaller concentric rectangle shape
void CreateMultiplePaths(void) { gxShape twoCircleShape, smallSquareShape; static rectangle smallSquareGeometry[] = {ff(90), ff(90), ff(110), ff(110)}; static long twoCircleGeometry[] = {2, /* # of contours */ 4, /* # of points */ 0xF0000000, /* 1111 ... */ ff(50), ff(50), ff(150), ff(50), ff(150), ff(150), ff(50), ff(150), 4, /* # of points */ 0xF0000000, /* 1111 ... */ ff(65), ff(65), ff(65), ff(135) , ff(135), ff(135), ff(135), ff(65)}; twoCircleShape = GXNewPaths((gxPaths *) twoCircleGeometry); GXSetShapeFill(twoCircleShape, gxEvenOddFill); smallSquareShape = GXNewRectangle(&smallSquareGeometry); GXSetShapeFill(smallSquareShape, gxEvenOddFill); GXDrawShape(twoCircleShape); GXDisposeShape(twoCircleShape); GXDrawShape(smallSquareShape); GXDisposeShape(smallSquareShape); }The results of this sample function are shown in Figure 4-50.Figure 4-50 A path shape with two contours and a smaller concentric rectangle shape
Since the
GXContainsShape
function considers shape fill when calculating whether one shape contains another, the following function call:
GXContainsShape(twoCircleShape, smallerCircleShape);returnsfalse
; the area covered by the larger path does not contain the area covered by the smaller path.For more information about the
GXContainsShape
function, see page 4-103.The functions
GXContainsRectangle
andGXContainsBoundsShape
work similarly to theGXContainsShape
function, except the input parameters to these functions are rectangle geometries, rather than shapes. TheGXContainsRectangle
function compares two rectangle geometries and theGXContainsBoundsShape
compares a rectangle geometry to a shape.For more information about the
GXContainsRectangle
function and theGXContainsBoundsShape
function, see page 4-100 and page 4-101, respectively.
Main | Page One | What's New | Apple Computer, Inc. | Find It | Contact Us | Help